import * as THREE from 'three';
class Light {
    constructor(Meteor3D){
        this.Meteor3D = Meteor3D
        this.helperVisible = true
        this.helperList = []
    }
    addpointLight(config){
        // 点光源
        const pointLight = new THREE.PointLight(0xffffff, 100, 1000);
        pointLight.castShadow = true;
        pointLight.shadow.mapSize.set(1024, 1024);
        pointLight.shadow.bias = -0.0005;
        pointLight.shadow.camera.near = 0.1;
        pointLight.shadow.camera.far = 100;
        pointLight.name='点光源'
        
        pointLight.position.copy(config.position);

        const sphereSize = 1;
        const pointLightHelper = new THREE.PointLightHelper( pointLight, sphereSize );
        pointLightHelper.name='点光源helper'
        pointLightHelper.isLightHelper = true
        pointLightHelper.visible = this.helperVisible
        
        this.Meteor3D.scene.add( pointLight );
        this.Meteor3D.scene.add( pointLightHelper );

        this.helperList.push(pointLightHelper)
    }
    addSpotLight(config){
        
        const spotLight = new THREE.SpotLight(0xffffff);
        spotLight.castShadow = true;
        spotLight.shadow.mapSize.width = 1024;
        spotLight.shadow.mapSize.height = 1024;
        spotLight.angle = Math.PI / 6;
        
        spotLight.distance = 30;
        spotLight.decay = 0.1;
        spotLight.power = 10;

        spotLight.name='聚光灯'
        spotLight.position.copy(config.position);

        const spotLightHelper = new THREE.SpotLightHelper( spotLight );
        spotLightHelper.name='聚光灯helper'
        spotLightHelper.isLightHelper = true
        spotLightHelper.visible = this.helperVisible

        this.Meteor3D.scene.add( spotLight );
        this.Meteor3D.scene.add( spotLightHelper );

        this.helperList.push(spotLightHelper)
        
        this.Meteor3D.addAnimationCallback(()=>{spotLightHelper.update()})
        
    }
    //控制helper显隐
    visibleHelper(visible){
        this.helperList.forEach(element => {
            element.visible = visible
        });
        this.helperVisible = visible
    }
}
export default Light;